//
//  popsortView.m
//  garbageclient
//
//  Created by Wang Wu on 11-8-10.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "popsortView.h"
#import "commondef.h"

const float PBTN_WIDTH = 300.0;
const float PBTN_HEIGHT = 30.0;

@implementation popsortView

@synthesize delegate;

- (void)dealloc
{
    [garbagebtn release];
    [popularbtn release];
    [newbtn release];
    [cancelbtn release];
    
    [super dealloc];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        garbagebtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        
        garbagebtn.frame = CGRectMake(10.0, 210.0, PBTN_WIDTH, PBTN_HEIGHT);
        [garbagebtn setTitle:@"最烂" forState:UIControlStateNormal];
        [garbagebtn setTitleColor:[UIColor redColor] forState:UIControlStateDisabled];
        [garbagebtn addTarget:self action:@selector(garbage:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:garbagebtn];
        
        popularbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        popularbtn.frame = CGRectMake(10.0, 260.0, PBTN_WIDTH, PBTN_HEIGHT);
        [popularbtn setTitle:@"人气" forState:UIControlStateNormal];
        [popularbtn setTitleColor:[UIColor redColor] forState:UIControlStateDisabled];
        [popularbtn addTarget:self action:@selector(popular:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:popularbtn];
        
        newbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        newbtn.frame = CGRectMake(10.0, 310.0, PBTN_WIDTH, PBTN_HEIGHT);
        [newbtn setTitle:@"最新" forState:UIControlStateNormal];
        [newbtn setTitleColor:[UIColor redColor] forState:UIControlStateDisabled];
        [newbtn addTarget:self action:@selector(new:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:newbtn];
        
        cancelbtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        cancelbtn.frame = CGRectMake(10.0, 360.0, PBTN_WIDTH, PBTN_HEIGHT);
        [cancelbtn setTitle:@"取消" forState:UIControlStateNormal];
        [cancelbtn addTarget:self action:@selector(cancelclick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:cancelbtn];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/
#pragma mark - btn click
-(void)garbage:(id)sender
{
    [delegate sortby:GARBAGE_PBT];
}

-(void)popular:(id)sender
{
    [delegate sortby:POPULAR_PBT];
}

-(void)new:(id)sender
{
    [delegate sortby:NEW_PBT];
}

-(void)cancelclick:(id)sender
{
    [delegate sortby:CANCEL_PBT];
}

#pragma mark - func
-(void)setSortType:(int) tp
{
    isorttype = tp;
    switch (isorttype) {
        case GARBAGE_PBT:
            [garbagebtn setEnabled:NO];
             break;
        case POPULAR_PBT:
            [popularbtn setEnabled:NO];
            break;
        case NEW_PBT:
            [newbtn setEnabled:NO];
            break;
        default:
            break;
    }
}

#pragma mark -touch
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    
}
@end
